package com.atstudy.headline.web.app.controller.login;

import com.atstudy.headline.login.LoginUserHolder;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.app.service.LoginService;
import com.atstudy.headline.web.app.vo.login.LoginVo;
import com.atstudy.headline.web.app.vo.users.UserLoginInfoVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/app")
public class AppLoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        String jwt = loginService.login(loginVo);
        return Result.ok( jwt );
    }

    /**
     * 获取用户信息
     * @param
     * @return
     */

    @GetMapping("/info")
    public Result<UserLoginInfoVo> info() {
        Integer userId = LoginUserHolder.getLoginUser().getUserId();
        UserLoginInfoVo userLoginInfoVo = loginService.getLoginUserInfoById(userId);
        return Result.ok(userLoginInfoVo);
    }

}
